package com.wx.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wx.token.AccessToken;

public class TokenUtil {
	private static Logger log = LoggerFactory.getLogger(TokenUtil.class);
	
	public static AccessToken getAccessToken() {
		String requestUrl = Constants.GET_ACCESSTOKEN_URL.replace("APPID",
				Constants.APPID).replace("APPSECRET", Constants.SECRET);
		String res = HttpUtil.get(requestUrl);
		ObjectMapper mapper = new ObjectMapper();
		AccessToken accessToken = null;
		try {
			accessToken = mapper.readValue(res, AccessToken.class);
			log.debug(accessToken.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return accessToken;
	}
}
